<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>桌面提醒(目前只支持Chrome5+)</title>
	<script type="text/javascript" src="js/jquery-1.11.2.js"></script>
</head>
<body>
	
</body>
<button onclick="init()">验证授权</button>&nbsp;
<button onclick="" id="notifyButton">弹出消息</button>
<script type="text/javascript">
	const miao = 5;

	function init(){
		alert(window.webkitNotifications);
		if(window.webkitNotifications){
			alert("2");
			window.webkitNotifications.requestPermission();
		}
	}

	function notify(){
		if(window.webkitNotifications.checkPermission()==0)
		{
			var popup = window.webkitNotifications.CreateNotification("images/logo.jpg","welcome","hello word!");
			popup.show();
		}
		else
		{
			window.webkitNotifications.requestPermission();
		}
	}


	document.getElementById('notifyButton').onclick = function(){
	//判断浏览器是否支持notification
	if(window.webkitNotifications){
	//判断当前页面是否被允许发出通知
	if(webkitNotifications.checkPermission==0){
	    var icon_url = 'http://www.w3.org/';
	    var title = 'Hello HTML5';
	    var body = 'I will be always here waiting for you!';
	    var WebkitNotification = webkitNotifications.createNotification(icon_url, title, body);
	    WebkitNotification.show();
	}else{
	    document.getElementById('requestbutton').onclick = function () {
	        webkitNotifications.requestPermission();
	    };
	}
	}else alert("您的浏览器不支持桌面通知特性，请下载谷歌浏览器试用该功能");
	};

</script>
</html>